﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace _28_MD5
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = GetMD5("123");
            //202cb962ac59075b964b07152d234b70
            Console.WriteLine(s);
            Console.ReadKey();
        }


        public static string GetMD5(string str)
        {
            MD5 md5 = MD5.Create();
            //将字符串转成字符数组
            byte[] buffer = Encoding.Default.GetBytes(str);
            //返回加密好的字符数组 
            byte[] md5Buffer = md5.ComputeHash(buffer);
            //return Encoding.Default.GetString(md5Buffer);
           
            //将数组中的每个元素ToString（）
            string strNew = "";
            for (int i = 0; i < md5Buffer.Length; ++i)
            {
                strNew += md5Buffer[i].ToString("x2");
            }
            return strNew;
        }
    }
}
